package com.peaker.advertisingpro.view

import android.app.Dialog
import android.content.Context
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.view.Window
import com.peaker.advertisingpro.R
import com.peaker.advertisingpro.utils.Common
import com.peaker.advertisingpro.utils.SPUtil
import kotlinx.android.synthetic.main.activity_test.*
import kotlinx.android.synthetic.main.layout_msg_dialog.*
import kotlinx.android.synthetic.main.layout_pwd_dialog.*

/**
 *  @ 作者 CODE_LYF
 *  @ 时间   2021/3/18.
 *  代码人生
 */
class MsgDialog(context: Context,var msg:String ="") : Dialog(context), View.OnClickListener {

    lateinit var onDialogSucced: (type: Int) -> Unit

    init {
        window?.requestFeature(Window.FEATURE_NO_TITLE)
        window?.setBackgroundDrawableResource(R.color.transparent)
        window.setGravity(Gravity.CENTER)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContentView(R.layout.layout_msg_dialog)
        setCanceledOnTouchOutside(false)
        btn_ok.setOnClickListener(this)
        btn_cancel.setOnClickListener(this)
        if (msg.isNotEmpty()){
            tv.setText(msg)
            btn_ok.visibility=View.GONE
            btn_cancel.visibility=View.GONE
        }

    }

    override fun onClick(v: View?) {
        when (v!!.id) {
            R.id.btn_ok -> {

                if (::onDialogSucced.isInitialized) {
                    onDialogSucced.invoke(0)
                }
                dismiss()
            }
            R.id.btn_cancel -> {
                if (::onDialogSucced.isInitialized) {
                    onDialogSucced.invoke(1)
                }
                dismiss()
            }
        }
    }


}